package com.example.jbmsuppliers.sinopec.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.jbmsuppliers.R;

import java.util.ArrayList;

/**
 * Created by 家帮忙 on 2016/9/28.
 */

public class MyRecy_photoAdapter extends RecyclerView.Adapter<MyRecy_photoAdapter.MyViewHolder> {
    Context c;
    ArrayList<Bitmap> listrecy;
    ImageView imageView;

    public MyRecy_photoAdapter(Context c, ArrayList<Bitmap> listrecy, ImageView imageView) {
        this.c = c;
        this.listrecy = listrecy;
        this.imageView = imageView;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(View.inflate(c, R.layout.item_recyl_photo_image,null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
    holder.img.setImageBitmap(listrecy.get(position));
   holder.delete.setVisibility(View.VISIBLE);
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listrecy.remove(listrecy.get(position));

                if (listrecy.size()==0){
                    imageView.setVisibility(View.VISIBLE);
                }
                notifyDataSetChanged();
            }
        });



    }




    @Override
    public int getItemCount() {
        return listrecy.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
//ImageView image_recyl_photo;
ImageView delete,img;
        public MyViewHolder(View itemView) {
            super(itemView);
//            image_recyl_photo= (ImageView) itemView.findViewById(R.id.image_recyl_photo);
            delete= (ImageView)itemView.findViewById(R.id.select_delete);
            img= (ImageView)itemView.findViewById(R.id.selectImg);
        }
    }


}
